﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using ReceiptPrint.Models;


namespace ReceiptPrint.ViewModels.ReceiptInfoVMs
{
    public partial class ReceiptInfoListVM : BasePagedListVM<ReceiptInfo_View, ReceiptInfoSearcher>
    {
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("ReceiptInfo", GridActionStandardTypesEnum.Create, Localizer["Sys.Create"],"", dialogWidth: 500,dialogHeight:400).SetQueryString($"pid={Searcher.TemplateId}"),
                this.MakeStandardAction("ReceiptInfo", GridActionStandardTypesEnum.Edit, Localizer["Sys.Edit"], "", dialogWidth: 500),
                this.MakeStandardAction("ReceiptInfo", GridActionStandardTypesEnum.Delete, Localizer["Sys.Delete"], "", dialogWidth: 500),
                //this.MakeStandardAction("ReceiptInfo", GridActionStandardTypesEnum.BatchDelete, Localizer["Sys.BatchDelete"], "", dialogWidth: 800),
            
            };
        }


        protected override IEnumerable<IGridColumn<ReceiptInfo_View>> InitGridHeader()
        {
            return new List<GridColumn<ReceiptInfo_View>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Price),
                this.MakeGridHeader(x => x.Number),
                this.MakeGridHeader(x => x.Tax),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<ReceiptInfo_View> GetSearchQuery()
        {
            var query = DC.Set<ReceiptInfo>().WhereIf(!string.IsNullOrEmpty(Searcher.TemplateId),x=>x.TemplateId == long.Parse(Searcher.TemplateId))
                .CheckContain(Searcher.Name, x=>x.Name)
                .Select(x => new ReceiptInfo_View
                {
				    ID = x.ID,
                    Name = x.Name,
                    Price = x.Price,
                    Number = x.Number,
                    Tax = x.Tax,
                    Name_view = x.Template.Name,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class ReceiptInfo_View : ReceiptInfo{
        [Display(Name = "名称")]
        public String Name_view { get; set; }

    }
}
